package com.tjetc.controller;

import com.github.pagehelper.PageInfo;
import com.tjetc.domain.Patient;
import com.tjetc.service.PatientService;
import com.tjetc.service.impl.PatientServiceImpl;
import com.tjetc.vo.Result;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (patient)表控制层
 *
 * @author xxxxx
 */
@RestController
@RequestMapping("/patient")
public class PatientController {
    /**
     * 服务对象
     */
    @Resource
    private PatientService patientService;

/**
* 通过主键查询单条数据
*
* @param id 主键
* @return 单条数据
*/
@RequestMapping("selectOne")
public Patient selectOne(@RequestParam("id") Integer id) {
    return patientService.selectByPrimaryKey(id);
}

    @RequestMapping("selectByUid")
    public List<Patient> selectByUid(@RequestParam("uid") Integer uid) {
        return patientService.selectByUid(uid);
    }
    @RequestMapping("addPatient")
    public Result addPatient(@RequestBody Patient patient) {
        return patientService.insertPatient(patient);
    }

    //upbind
    @RequestMapping("upbind")
    public Result upbind(@RequestParam("id") Integer id) {
        return patientService.upbind(id);
    }

    //selectByUidUnBind
    @RequestMapping("selectByUidUnBind")
    public List<Patient> selectByUidUnBind(@RequestParam("uid") Integer uid) {
        return patientService.selectByUidUnBind(uid);
    }

    @RequestMapping("updatePatient")
    public Result updatePatient(@RequestBody Patient patient) {
        return patientService.updatePatient(patient);
    }

    @GetMapping("checkIdCard")
    public Result checkIdCard(@RequestParam("id") Integer id,@RequestParam("input") String input) {
        return patientService.checkIdCard(id,input);
    }
    @RequestMapping("findAllPatient")
    public PageInfo<Patient> findAllPatient(
            @RequestParam(value = "curPage",defaultValue = "1") Integer curPage,
            @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
            @RequestParam("name") String name) {
        return patientService.findAllPatient(curPage,pageSize,name);
    }
}
